//
//  GgfwMainViewController.m
//  上海杨浦
//
//  Created by FrankChen on 13-5-23.
//  Copyright (c) 2013年 FrankChen. All rights reserved.
//

#import "GgfwMainViewController.h"
#import "CydhSubView.h"
#import "BmwdViewController.h"
#import "BmggViewController.h"
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) 
#define IOS_VERSION_7_OR_ABOVE (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)? (YES):(NO))

@implementation GgfwMainViewController
@synthesize Btn_back;
@synthesize EGOview;
@synthesize imageView1;
@synthesize scrollview;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    diff=0;
    if (iPhone5) {
        diff=88;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }
    [self AddImageView];
    [self addBtns:[self AddScrollView]];
}

-(void)AddImageView{
    UIImageView *imageView=[[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 420+diff)]autorelease];
    [imageView setImage:[UIImage imageNamed:@"bgImg_ggfw.png"]];
    [self.view addSubview:imageView];
}

-(UIScrollView *)AddScrollView{
    UIScrollView *scrollView=[[[UIScrollView alloc]initWithFrame:CGRectMake(0, 160+diff/1.7, 320, 411)]autorelease];
    //[scrollView setBackgroundColor:[UIColor grayColor]];
    [scrollView setContentSize:CGSizeMake(320, 500)];
    [self.view addSubview:scrollView];
    scrollview=scrollView;
    return scrollView;
    
}

-(void)addBtns:(UIScrollView *)ScrollView{
    [self addBtnToScrollView:ScrollView :10 :@"btn_bmwd.png" :1];
    [self addBtnToScrollView:ScrollView :110 :@"btn_bmgg.png" :2];
    [self addBtnToScrollView:ScrollView :210 :@"btn_cydh.png" :3];
}

-(void)addBtnToScrollView:(UIScrollView *)ScrollView :(int) y_zuobiao :(NSString *)img :(int)flag{
    CGRect frame=CGRectMake(25, y_zuobiao, 270, 83);
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:img] forState:UIControlStateNormal];
    btn.frame = frame;
    switch (flag) {
        case 1:
            [btn addTarget:self action:@selector(Button1Clicked) forControlEvents:UIControlEventTouchUpInside];
            [btn addTarget:self action:@selector(Button11Clicked) forControlEvents:UIControlEventTouchDown];
            break;
        case 2:
            [btn addTarget:self action:@selector(Button2Clicked) forControlEvents:UIControlEventTouchUpInside];
            [btn addTarget:self action:@selector(Button22Clicked) forControlEvents:UIControlEventTouchDown];
            break;
        case 3:
            [btn addTarget:self action:@selector(Button3Clicked) forControlEvents:UIControlEventTouchUpInside];
            [btn addTarget:self action:@selector(Button33Clicked) forControlEvents:UIControlEventTouchDown];
            break;
            
    }
    
    [ScrollView addSubview:btn];
}

-(void)Button11Clicked{downflag=1;}
-(void)Button22Clicked{downflag=2;}
-(void)Button33Clicked{downflag=3;}

-(void)Button1Clicked{
    if (downflag==1) {
        BmwdViewController *bmwd=[[BmwdViewController alloc]init];
        EGOview=bmwd.view;
        [self.view addSubview:bmwd.view];
        [self AddImageView:1];
    }
}

-(void)Button2Clicked{
    if (downflag==2) {
        BmggViewController *bmgg=[[BmggViewController alloc]init];
        EGOview=bmgg.view;
        [self.view addSubview:bmgg.view];
        [self AddImageView:2];
    }
}

-(void)Button3Clicked{
    if (downflag==3) {
        //[scrollview removeFromSuperview];
        CydhSubView *cydhView=[[CydhSubView alloc]initWithFrame:CGRectMake(0, 87+diff/1.7, 320, 411)];
        [self.view addSubview:cydhView];
    }
}

-(void) AddImageView:(int)flag{
    UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 87+diff/1.7, 320, 30)];
    [imageView setBackgroundColor:[UIColor blueColor]];
    imageView1=imageView;
    [self.view addSubview:imageView];
    [self AddLabel:imageView :flag];
    [self AddBtn_back];
}

-(void) AddLabel:(UIImageView *)imageView :(int)flag{
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(124, 1, 80, 28)];
    UIFont *font=[UIFont fontWithName:@"FZHTJW--GB1-0" size:18.0f];
    [label setFont:font];
    [label setBackgroundColor:[UIColor blueColor]];
    [label setTextColor:[UIColor whiteColor]];
    switch (flag) {
        case 1:{
            [label setText:@"便民问答"];
            break;}
        case 2:{
            [label setText:@"便民公告"];
            break;}
    }
    [imageView addSubview:label];
}

-(void)AddBtn_back{
    CGRect frame=CGRectMake(21, 87+diff/1.7, 72, 29);
    UIButton *btn_back=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn_back setTag:50];
    [btn_back setImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateNormal];
    btn_back.frame=frame;
    [btn_back addTarget:self action:@selector(Btn_back_Clicked) forControlEvents:UIControlEventTouchUpInside];
    [[self view]addSubview:btn_back];
    Btn_back=btn_back;
}

-(void)Btn_back_Clicked{
    [EGOview removeFromSuperview];
    [Btn_back removeFromSuperview];
    [imageView1 removeFromSuperview];
}

@end































